<style type="text/css">
    td.dataPick{
        position: relative;
        height:30px;
    }
    
    .dataPick span.error {
        position: absolute !important;
        left: 151px;
    }
    
    #orderTbody tr td div {
        height: 29px;
        padding-top: 3px;
    }
    
    .processStatus span.error {
        position: absolute !important;
        left: 121px;
    }
    
    tr.notOverToday{
        background-color: #F99DA8;
    }
    

</style>
<form method="post" id="productOrder_split" action="${rc.getContextPath()}/manage/productOrder/saveProductionOrder" class="pageForm required-validate" onsubmit="return productOrderDecompose.validateCallback(this)">
<div class="pageContent">
    <input type="hidden" name="navTabId" value="${navTabId!''}" />
    <div class="pageFormContent">
        <fieldset>
            <dl>
                <dt><@label key='productOrderNum.C,colon'>产品订单编号：</@label></dt>
                <dd><input type="text" name="productOrderNum" maxlength="20" value="${productOrder.productOrderNum!''}" readonly="readonly"></dd>
            </dl>
            <dl>
                <dt><@label key='plannedQuantity.C,colon'>计划数量</@label></dt>
                <dd><input type="text" name="plannedQuantity" readonly="readonly" value="${productOrder.plannedQuantity!''}"/></dd>
            </dl>
            <dl>
                <dt><@label key='decomposedQuantity.C,colon'>已分解数量</@label></dt>
                <dd><input type="text" name="decomposedQuantity" readonly="readonly" min="0" value="${productOrder.decomposedQuantity!''}"/></dd>
            </dl>
            <dl>
                <dt><@label key='decompositionQuantity.C,colon'>分解数量</@label></dt>
                <dd><input type="text" name="decompositionQuantity" class="required digits" min="1" max="${productOrder.decompositionQuantity!''}" value="${productOrder.decompositionQuantity!''}"/></dd>
            </dl>
        </fieldset>
        <table class="table border canopration" width="160%" layoutH="140">
            <thead>
                <tr>
                    <th width="20"><@label key="serialNumber.C">序号</@label></th>
                    <th width="80"><@label key='materialCode.C'>物料编号</@label></th>
                    <th width="80"><@label key='materialText.C'>物料名称</@label></th>
                    <!-- <th width="60"><@label key='plannedQuantity.C'>计划数量</@label></th> -->
                    <th width="120"><@label key='orderType.C'>订单类型</@label></th>
                    <th width="140"><@label key='requirementDate.C'>需求日期</@label></th>
                    <th width="140"><@label key='plannedstartDateTime.C'>计划开始时间</@label></th>
                    <th width="140"><@label key='plannedendDateTime.C'>计划结束时间</@label></th>
                    <th width="120"><@label key='cmprocess_name.C'>工艺名称</@label></th>
                    <th width="50"><@label key='cmprocessrev.C'>工艺版本</@label></th>
                    <th width="70"><@label key='productionlotNum.C'>生产批次号</@label></th>
                </tr>
            </thead>
            <tbody id="orderTbody">
            <#if productionOrders??><#if (productionOrders?size>0 )>
                <#list productionOrders as order>
                <tr style="height:30px" <#if order.overToday?string('true','false')=='false'>class="notOverToday"</#if> >
                    <td style='position: relative;height:30px;'>${order_index + 1}<input type="hidden" name="productionOrder[${order_index}].parentOrderNum" value="${order.parentOrderNum!''}"></td>
                    <td>${order.materialCode!''}
                    <input type="hidden" name="productionOrder[${order_index}].materialCode" value="${order.materialCode!''}"/>
                    <input type="hidden" name="productionOrder[${order_index}].plannedQuantity" value="${order.plannedQuantity!''}"/>
                    </td>
                    <td>${order.materialText!''}</td>
                    <!-- <td>${order.plannedQuantity!''}<input type="hidden" name="productionOrder[${order_index}].plannedQuantity" value="${order.plannedQuantity!''}"/></td> -->
                    <td class="processStatus">
                        <select name="productionOrder[${order_index}].orderTypeCode" class="required" style="width:120px">
                        <option value="" ></option>
                        <#if orderTypes??>
                            <#list orderTypes as orderType>
                                <option value="${orderType.orderTypeCode!''}" <#if productOrder.orderTypeCode?? && productOrder.orderTypeCode == orderType.orderTypeCode> selected</#if> >${orderType.orderTypeText!''}</option>
                            </#list>
                        </#if>
                    </select>
                    </td>
                    <td class="dataPick"><input type="text" name="productionOrder[${order_index}].requirementDate" readonly class="date textInput required" value="${(productOrder.requirementDate?string('yyyy-MM-dd'))?if_exists}"/>
                        <a class="inputDateButton" href="javascript:;">选择</a>
                    </td>
                    <td class="dataPick"><input type="text" name="productionOrder[${order_index}].plannedstartDateTime" readonly class="date required textInput" dateFmt="yyyy-MM-dd HH:mm:ss" 
                        max_date="{productionOrder[${order_index}].plannedendDateTime}" value="${(order.plannedstartDateTime?string('yyyy-MM-dd HH:mm:ss'))?if_exists}"/> <a class="inputDateButton" href="javascript:;">选择</a>
                    </td>
                    <td class="dataPick"><input type="text" name="productionOrder[${order_index}].plannedendDateTime" readonly class="date required textInput" dateFmt="yyyy-MM-dd HH:mm:ss" 
                        min_date={productionOrder[${order_index}].plannedstartDateTime} value="${(order.plannedendDateTime?string('yyyy-MM-dd HH:mm:ss'))?if_exists}"/> <a class="inputDateButton" href="javascript:;">选择</a>
                    </td>
                    <td class="processStatus">
                        <select target="pp_processCode" processRev="processRev_${order_index}" name="productionOrder[${order_index}].processCode" class="required" style="width:120px">
                            <option value="" ></option>
                            <#if order.processes??>
                                <#list order.processes as process>
                                    <option value="${process.processCode!''}@_@${process.processRev!''}">${process.processText!''}</option>
                                </#list>
                            </#if>
                        </select>
                    </td>
                    <td id="processRev_${order_index}"><input type="hidden" id="processRev_${order_index}" name="productionOrder[${order_index}].processRev"/></td>
                    <td><input type="text" style="width:100px" maxlength="40" class="textInput" name="productionOrder[${order_index}].productionlotNum"  value="${productOrder.productionlotNum!''}"/></td>
                    
                </tr>
            </#list>
            </#if></#if>
            </tbody>
        </table>
    </div>
    <div class="formBar">
        <ul>
            <li><div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div></li>
            <li>
                <div class="buttonActiveGrey"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
            </li>
        </ul>
    </div>
</div>
</form>
<script type="text/javascript">
    $(function(){
        $("select[target='pp_processCode']",$.pdialog.getCurrent()).change(function(){
            var $this = $(this);
            var processRev = $this.attr("processRev");
            var value = $this.val();
            $("td#"+processRev, $.pdialog.getCurrent()).find("div").html(value.split("@_@")[1]);
        });
    });
    
    var productOrderDecompose = {
    		
    	validateCallback : function(form) {
    		var flag = true;
    		$("input[name$='plannedstartDateTime']").each(function(){
    			var value = $(this).val();    			
    			if(value && value.parseDate('yyyy-MM-dd HH:mm:ss').getTime() < new Date().getTime()){
    				flag = false;
    			}
    			return flag;
    		});
    		if(!flag){
    			alertMsg.confirm("存在计划开始时间小于当前时间的订单数据，是否确认分解!",{
                    okCall: function(){
                        return validateCallback(form, dialogAjaxDone);
                    }
                });
    			return false;
    		}else{
    			return validateCallback(form, dialogAjaxDone);
    		}
    	}
    }
</script>